//
//  ShareHanler.m
//  iPlan
//
//  Created by 侯伟 on 2021/9/3.
//

#import "ShareHanler.h"
@implementation ShareHanler

+ (void)share:(NSString*)title image:(UIImage*)image url:(NSString*)url;{
    
    NSMutableArray* items = [NSMutableArray array];
    
    if(title.length){
        [items addObject:title];
    }
    if(image){
        [items addObject:image];
    }
    if(url.length){
        NSURL* shareUrl = [NSURL URLWithString:url];
        if(shareUrl){
            [items addObject:shareUrl];
        }
    }
    
    if(!items.count) return;
    
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    activityVC.modalInPopover = YES;
    activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
        if (completed) {
            [Toast toast:@"分享成功"];
        }else{
            [Toast toast:@"分享失败"];
        }
    };
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activityVC animated:YES completion:nil];
}

+(void)shareAPP{
    [ShareHanler share:@"超全影视" image:[UIImage imageNamed:@"a_share_icon"] url:APP_SHARE_URL];
}



@end
